//搭建服务器
const express = require('express')
const path = require('path')
require('./db')

//引入数据库集合对象
// const adminModel = require('./db/model/adminModel')

//引入外部路由
const addAdminRoute = require('./routes/addAdmin')
const adminListRoute = require('./routes/adminList')
const deleteAdminRoute = require('./routes/deleteAdmin')
const loginRoute = require('./routes/login')
const logoutRoute = require('./routes/logout')
const addAdvRoute = require('./routes/addAdv')
const advListRoute = require('./routes/advList')
const deleteAdvRoute = require('./routes/deleteAdv')
const getUpdateDataRoute = require('./routes/getUpdateData')
const updateAdvRoute = require('./routes/updateAdv')

const app = express()


//引入处理请求体的中间件
app.use(express.urlencoded())
app.use(express.json())


//暴露静态资源文件夹!!!!!
app.use('/upload',express.static(path.resolve(__dirname,'./upload')))

//添加管理员逻辑
//使用路由
app.use(addAdminRoute)
app.use(adminListRoute)
app.use(deleteAdminRoute)
app.use(loginRoute)
app.use(logoutRoute)
app.use(addAdvRoute)
app.use(advListRoute)
app.use(deleteAdvRoute)
app.use(getUpdateDataRoute)
app.use(updateAdvRoute)

app.listen(8000, () => {
  console.log('服务器启动成功');
})